# 导包  selenium自动登录
from selenium import webdriver
import time
from selenium.webdriver import ActionChains

# 建立浏览器对象
browser = webdriver.Chrome('G:\\July\\Git\\Go\\chromedriver.exe')

# 打开网址
browser.get('http://localhost:8080/login2')

time.sleep(1)

# 填入用户名密码
browser.find_elements_by_tag_name('input')[0].send_keys('fjkss')
browser.find_elements_by_tag_name('input')[1].send_keys('123')

time.sleep(2)

# 定义拖动对象
button = browser.find_element_by_class_name('dv_handler')

box = browser.find_element_by_class_name('dv_text')
# print(button)

# 获取按钮长度
square_len = button.size.get('width')

# 获取滚动条长度
box_len = box.size.get('width')
print(square_len)
print(box_len)

# 定义动作对象
action = ActionChains(browser)

# 定义动作类型
action.click_and_hold(button).perform()

# 释放动作
action.reset_actions()

# 拖动举例
action.move_by_offset((box_len-square_len), 0).perform()

# 点击登录按钮
browser.find_element_by_class_name('log').click()

time.sleep(10)

browser.close()
